home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / TOUCH.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  1KB  |  57 lines

  1. .I 4 2
  2. * Updated:     13 Feb 93 Thad Smith                                     *
  3. * Updated:     15 Feb 93 Bob Stout                                      *
  4. .D 5 1
  5. .I 11 10
  6. #include <stdlib.h>
  7. #include <time.h>
  8. #ifdef __TURBOC__
  9.  #include <dos.h>
  10.  #include <io.h>
  11. #else
  12.  #include "ftime.h"                 /* Borland work-alike in SNIPPETS   */
  13. #endif
  14.  
  15. void usage(void);
  16. .D 12 2
  17. .I 16 38
  18.       time_t    tnow;
  19.       struct tm tmnow;
  20.       struct ftime ft;
  21.       FILE *f;
  22.  
  23.       if (argc < 2)
  24.             usage();
  25.  
  26.       tnow  = time(NULL);
  27.       tmnow = *localtime(&tnow);
  28.  
  29.       ft.ft_year  = tmnow.tm_year - 80;
  30.       ft.ft_month = tmnow.tm_mon + 1;
  31.       ft.ft_day   = tmnow.tm_mday;
  32.       ft.ft_hour  = tmnow.tm_hour;
  33.       ft.ft_min   = tmnow.tm_min;
  34.       ft.ft_tsec  = tmnow.tm_sec/2;
  35.  
  36.       if ((f = fopen(argv[1], "r+b")) != NULL)
  37.             setftime(fileno(f), &ft);
  38.       else if ((f = fopen(argv[1], "w")) != NULL)
  39.             setftime(fileno(f), &ft);
  40.       else  perror("Can't open file");
  41.  
  42.       if (f)
  43.             fclose(f);
  44.  
  45.       return EXIT_SUCCESS;
  46. }
  47.  
  48. void usage(void)
  49. {
  50.       puts("Usage: TOUCH filename\n");
  51.       puts("  The timestamp of filename will be set to the current time.");
  52.       puts("  A zero-length file will be created if the file doesn't exist.");
  53.       exit(EXIT_FAILURE);
  54. }
  55.  
  56. .D 17 29
  57.